package com.tj.collection.controller.lending.response;

import com.fqgj.common.api.ResponseData;
import com.fqgj.common.utils.DateUtil;
import com.tj.collection.db.entity.business.ClPaidEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: pavan
 * Date: 2020/2/8
 * Time: 下午6:26
 */
public class ClPaidListResponse implements ResponseData {

    private List<Item> paidList;

    private List<String[]> itemList;

    public ClPaidListResponse(List<ClPaidEntity> clPaidEntityList) {
        this.paidList = new ArrayList<>();
        for (ClPaidEntity entity : clPaidEntityList) {
            Item item = new Item();
            item.setMerchantCode(entity.getMerchantCode());
            item.setProductCategory(entity.getProductCategory());
            item.setAppName(entity.getAppName());
            item.setTradeNo(entity.getTradeNo());
            item.setRepaymentDate(DateUtil.getDate(entity.getRepaymentDate(), "yyyy-MM-dd HH:mm:ss"));
            item.setNotificationTime(DateUtil.getDate(entity.getNotificationTime(), "yyyy-MM-dd HH:mm:ss"));
            item.setSettlementTime(DateUtil.getDate(entity.getSettlementTime(), "yyyy-MM-dd HH:mm:ss"));
            item.setRepayBizNo(entity.getRepayBizNo());
            item.setResult(entity.getResult());
            item.setOverdueDays(entity.getOverdueDays() + "");
            item.setAgent(entity.getAgent());
            item.setBucket(entity.getBucket());
            item.setBorrowCapital(entity.getBorrowCapital() == null ? "" : entity.getBorrowCapital().toString());
            item.setInterest(entity.getInterest() == null ? "" : entity.getInterest().toString());
            item.setPenalty(entity.getPenalty() == null ? "" : entity.getPenalty().toString());
            item.setPaidAmount(entity.getPaidAmount() == null ? "" : entity.getPaidAmount().toString());
            item.setDeductAmount(entity.getDeductAmount() == null ? "" : entity.getDeductAmount().toString());
            this.paidList.add(item);
        }
    }

    public ClPaidListResponse(List<ClPaidEntity> clPaidEntityList, boolean isExport) {
        this.itemList = new ArrayList<>();
        String[] row1 = {
                "Merchant", "App Name", "LoanId", "Repayment Date", "Notification Time",
                "Settlement Time", "RepayBizNo", "Result", "Overduedays", "Agent",
                "Bucket", "LoanAmount", "Interest", "Penalty", "ActualAmountPaid",
                "DiscountAmount"
        };

        this.itemList.add(row1);

        for (ClPaidEntity entity : clPaidEntityList) {
            String[] row = new String[row1.length];
            row[0] = entity.getMerchantCode();
            row[1] = entity.getAppName();
            row[2] = entity.getTradeNo();
            row[3] = DateUtil.getDate(entity.getRepaymentDate(), "yyyy-MM-dd HH:mm:ss");
            row[4] = DateUtil.getDate(entity.getNotificationTime(), "yyyy-MM-dd HH:mm:ss");
            row[5] = DateUtil.getDate(entity.getSettlementTime(), "yyyy-MM-dd HH:mm:ss");
            row[6] = entity.getRepayBizNo();
            row[7] = entity.getResult();
            row[8] = entity.getOverdueDays() + "";
            row[9] = entity.getAgent();
            row[10] = entity.getBucket();
            row[11] = entity.getBorrowCapital() == null ? null : entity.getBorrowCapital().toString();
            row[12] = entity.getInterest() == null ? null : entity.getInterest().toString();
            row[13] = entity.getPenalty() == null ? null : entity.getPenalty().toString();
            row[15] = entity.getPaidAmount() == null ? null : entity.getPaidAmount().toString();
            row[16] = entity.getDeductAmount() == null ? null : entity.getDeductAmount().toString();
            this.itemList.add(row);
        }
    }

    private class Item {
        private String merchantCode;
        private String productCategory;
        private String appName;
        private String tradeNo;
        private String repaymentDate;
        private String notificationTime;
        private String settlementTime;
        private String repayBizNo;
        private String result;
        private String overdueDays;
        private String agent;
        private String bucket;
        private String borrowCapital;
        private String interest;
        private String penalty;
        private String paidAmount;
        private String deductAmount;

        public String getMerchantCode() {
            return merchantCode;
        }

        public Item setMerchantCode(String merchantCode) {
            this.merchantCode = merchantCode;
            return this;
        }

        public String getProductCategory() {
            return productCategory;
        }

        public Item setProductCategory(String productCategory) {
            this.productCategory = productCategory;
            return this;
        }

        public String getAppName() {
            return appName;
        }

        public Item setAppName(String appName) {
            this.appName = appName;
            return this;
        }

        public String getTradeNo() {
            return tradeNo;
        }

        public Item setTradeNo(String tradeNo) {
            this.tradeNo = tradeNo;
            return this;
        }

        public String getRepaymentDate() {
            return repaymentDate;
        }

        public Item setRepaymentDate(String repaymentDate) {
            this.repaymentDate = repaymentDate;
            return this;
        }

        public String getNotificationTime() {
            return notificationTime;
        }

        public Item setNotificationTime(String notificationTime) {
            this.notificationTime = notificationTime;
            return this;
        }

        public String getSettlementTime() {
            return settlementTime;
        }

        public Item setSettlementTime(String settlementTime) {
            this.settlementTime = settlementTime;
            return this;
        }

        public String getRepayBizNo() {
            return repayBizNo;
        }

        public Item setRepayBizNo(String repayBizNo) {
            this.repayBizNo = repayBizNo;
            return this;
        }

        public String getResult() {
            return result;
        }

        public Item setResult(String result) {
            this.result = result;
            return this;
        }

        public String getOverdueDays() {
            return overdueDays;
        }

        public Item setOverdueDays(String overdueDays) {
            this.overdueDays = overdueDays;
            return this;
        }

        public String getAgent() {
            return agent;
        }

        public Item setAgent(String agent) {
            this.agent = agent;
            return this;
        }

        public String getBucket() {
            return bucket;
        }

        public Item setBucket(String bucket) {
            this.bucket = bucket;
            return this;
        }

        public String getBorrowCapital() {
            return borrowCapital;
        }

        public Item setBorrowCapital(String borrowCapital) {
            this.borrowCapital = borrowCapital;
            return this;
        }

        public String getInterest() {
            return interest;
        }

        public Item setInterest(String interest) {
            this.interest = interest;
            return this;
        }

        public String getPenalty() {
            return penalty;
        }

        public Item setPenalty(String penalty) {
            this.penalty = penalty;
            return this;
        }

        public String getPaidAmount() {
            return paidAmount;
        }

        public Item setPaidAmount(String paidAmount) {
            this.paidAmount = paidAmount;
            return this;
        }

        public String getDeductAmount() {
            return deductAmount;
        }

        public Item setDeductAmount(String deductAmount) {
            this.deductAmount = deductAmount;
            return this;
        }
    }
}
